/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare.data');
(function () {
	
	/**
	 * model year code: 0
	 * model year desc: 1
	 * make code: 2
	 * make desc: 3
	 * model code: 4
	 * model desc: 5
	 * trim code: 6
	 * trim desc: 7
	 * trim variation: 8
	 */
	
	ASC.loadBundle({
		locale: 'en_CA',
	    messages: {
	        'net.autodata.compare.data.format.ymmt': '{1} {3} {5} {7}',
	        'net.autodata.compare.data.format.ym': '{1} {3}',
	        'net.autodata.compare.data.format.mm': '{3} {5}',
	        'net.autodata.compare.data.format.ymm': '{1} {3} {5}',
	        'net.autodata.compare.data.format.mt': '{5} {7}'
	    }
	});
	
	ASC.loadBundle({
		locale: 'en_US',
	    messages: {
	        'net.autodata.compare.data.format.ymmt': '{1} {3} {5} {7}',
	        'net.autodata.compare.data.format.ym': '{1} {3}',
	        'net.autodata.compare.data.format.mm': '{3} {5}',
	        'net.autodata.compare.data.format.ymm': '{1} {3} {5}',
	        'net.autodata.compare.data.format.mt': '{5} {7}'
	    }
	});
	
	/**
	 * @class Format
	 * @extends Object
	 * @singleton
	 * @namespace net.autodata.compare.data
	 */
	var Format = {
			
		/**
		 * Model Year Make Model Trim
		 * @return String 
		 */	
		ymmt: function (vehicle) 
		{
			return this.format('ymmt', vehicle);
		},
		
		/**
		 * Model Year Make
		 */
		ym: function (vehicle)
		{
			return this.format('ym', vehicle);
		},
		
		/**
		 * Make Model
		 * @return String
		 */
		mm: function (vehicle)
		{
			return this.format('mm', vehicle);
		},
		
		/**
		 * Model Year Make Model
		 * @return String
		 */
		ymm: function (vehicle)
		{
			return this.format('ymm', vehicle);
		},
		
		/**
		 * Model Trim
		 * @return String
		 */
		mt: function (vehicle)
		{
			return this.format('mt', vehicle);
		},
		
		format: function (key, vehicle)
		{
			var s = ASC.message('net.autodata.compare.data.format.' + key);
			v = this.flattenVehicle(vehicle);
			
			return String.format(s, v.modelYearCode, v.modelYear, v.makeCode, v.make, 
									v.modelCode, v.model, v.trimCode, v.trim, v.trimVariation);
		},
		
		flattenVehicle: function (vehicle)
		{	
			//check to see if this object has already been flattened
			if (!vehicle.modelYear.code) {
				return vehicle;
			}
			
			return {
				modelYearcode: vehicle.modelYear.code,
				modelYear: vehicle.modelYear.description,
				makeCode: vehicle.make.code,
				make: vehicle.make.description,
				modelCode: vehicle.model.code,
				model: vehicle.model.description,
				trimCode: vehicle.trim.code,
				trim: vehicle.trim.description,
				trimVariation: vehicle.trim.variation
			};
		}
	};
	
	net.autodata.compare.data.Format = Format;
	
})();